package com.szyportal.web.back.controller.szyportal;

import com.szyportal.common.annotation.Log;
import com.szyportal.common.core.controller.BaseController;
import com.szyportal.common.core.domain.AjaxResult;
import com.szyportal.common.core.page.TableDataInfo;
import com.szyportal.common.enums.BusinessType;
import com.szyportal.common.utils.StringUtils;
import com.szyportal.common.utils.poi.ExcelUtil;
import com.szyportal.custom.domain.WAbout;
import com.szyportal.custom.service.IWAboutService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 关于我们Controller
 * 
 * @author ruoyi
 * @date 2024-12-03
 */
@Controller
@RequestMapping("/back/custom/about")
public class WAboutController extends BaseController
{
    private String prefix = "back/szyportal/about";

    @Autowired
    private IWAboutService wAboutService;

    @RequiresPermissions("system:about:view")
    @GetMapping()
    public String about()
    {
        return prefix + "/about";
    }

    /**
     * 查询关于我们列表
     */
    @RequiresPermissions("system:about:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WAbout wAbout)
    {
        startPage();
        List<WAbout> list = wAboutService.selectWAboutList(wAbout);
        return getDataTable(list);
    }

    /**
     * 导出关于我们列表
     */
    @RequiresPermissions("system:about:export")
    @Log(title = "关于我们", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WAbout wAbout)
    {
        List<WAbout> list = wAboutService.selectWAboutList(wAbout);
        ExcelUtil<WAbout> util = new ExcelUtil<WAbout>(WAbout.class);
        return util.exportExcel(list, "关于我们数据");
    }

    /**
     * 新增关于我们
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存关于我们
     */
    @RequiresPermissions("system:about:add")
    @Log(title = "关于我们", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WAbout wAbout)
    {
        return toAjax(wAboutService.insertWAbout(wAbout));
    }

    /**
     * 修改关于我们
     */
    @RequiresPermissions("system:about:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WAbout wAbout = wAboutService.selectWAboutById(id);
        mmap.put("wAbout", wAbout);
        return prefix + "/edit";
    }

    /**
     * 修改保存关于我们
     */
    @RequiresPermissions("system:about:edit")
    @Log(title = "关于我们", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WAbout wAbout)
    {
        if (StringUtils.isEmpty(wAbout.getImg())) {
            WAbout wAbout1 = wAboutService.selectWAboutById(wAbout.getId());
            String img = wAbout1.getImg();
            if (!StringUtils.isEmpty(img)) {
                wAbout.setImg(img);
            }
        }
        return toAjax(wAboutService.updateWAbout(wAbout));
    }

    /**
     * 删除关于我们
     */
    @RequiresPermissions("system:about:remove")
    @Log(title = "关于我们", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wAboutService.deleteWAboutByIds(ids));
    }
}
